/**
 * Description:
 * Class Name:ExHandler
 * Date:2022/5/8 16:01
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第16章_多线程._16_7_线程组和未处理的异常;

public class ExHandler implements Thread.UncaughtExceptionHandler{
    @Override
    public void uncaughtException(Thread t, Throwable e) {
        System.out.println("线程：" + t.getName() + " 出现了异常：" + e);
    }

    public static void main(String[] args) {
        // 设置主线程的异常处理器
        Thread.currentThread().setUncaughtExceptionHandler(new ExHandler());
        var a = 5 / 0;
        System.out.println("程序正常结束");
    }
}
// 线程：main 出现了异常：java.lang.ArithmeticException: / by zero